const { Article } = require('../../model/article');
module.exports = async (req,res)=>{
  //根据传过来的id查找文章
  let article = await Article.findOne({_id: req.query.id});
  if(article){
    if(article.state == 1 ) {
      await Article.findByIdAndUpdate(req.query.id, {
        state: 0
      });
      res.redirect('/admin/toArticleListPage');
    }else if(article.state == 0 ){
      await Article.findByIdAndUpdate(req.query.id, {
        state: 1
      });
      res.redirect('/admin/toArticleListPage');
    }
  }else{
    res.render('admin/articleList',{
      message: '修改状态失败！！！'
    });
  }
}